package com.bluejie.bluej.java.design.chain;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by bluej on 2018/2/1.
 */
public class ChainDemo {
    private static ChainDemo chainDemo =new ChainDemo();

    public static void main(String[] args) {
        chainDemo.execute().doExecutor();
    }

    private Executor execute(){

        Executor executor = new ExecutorService();
        List<Handler> handleList  = new ArrayList<>();
        handleList.add(new LogHandler());
        handleList.add(new ParamaterHandler());
        handleList.add(new ServiceHandler());
        Collections.reverse(handleList);

        for (int i = 0 ;i<handleList.size(); i++) {
            System.out.println(i);
            final  Handler handle = handleList.get(i);
            final Executor executorAgain = executor;
            executor = new Executor() {
                @Override
                public void doExecutor() {
                    handle.doHandle(executorAgain);
                }
            };
        }
        return executor;

    }

}
